package com.neusoft.neps.controller;

import com.neusoft.grid.entity.Mission;
import com.neusoft.neps.method.MissionIO;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class FeedbackListController {

    @FXML
    private ListView<String> feedbackListView;

    @FXML
    public void initialize() throws IOException {
        // 加载当前用户的反馈
        List<Mission> missions = new ArrayList<>();
        missions = MissionIO.readMissions("missions.txt");
        for (Mission mission : missions){
            feedbackListView.getItems().add(mission.toString());
        }
    }

    @FXML
    private void handleBack() {
        try {
            navigateTo("../view/SelectAqiView.fxml");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void navigateTo(String fxmlPath) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        Stage stage = (Stage) feedbackListView.getScene().getWindow();
        URL url = getClass().getResource(fxmlPath);
        fxmlLoader.setLocation(url);
        Parent root = fxmlLoader.load();
        Scene scene = new Scene(root, 600, 400);
        stage.setScene(scene);
        stage.show();
    }
}